package com.ymttest.database.mongo.converter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

public abstract class YmtConverters {
	
	public static List<Converter<?, ?>> getConvertersToRegister() {
		List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
		converters.add(LongToBigDecimalConverter.INSTANCE);
		converters.add(BigDecimalToLongConverter.INSTANCE);
		return converters;
	}
	
	public static enum BigDecimalToLongConverter implements Converter<BigDecimal, Long>{
		INSTANCE;

		@Override
	    public Long convert(BigDecimal source) {
	        return source.multiply(new BigDecimal(100)).longValue();
	    }
	}
	
	public static enum LongToBigDecimalConverter implements Converter<Long, BigDecimal> {
		INSTANCE;

		@Override
		public BigDecimal convert(Long source) {
			return new BigDecimal(source).divide(new BigDecimal(100)).setScale(2);
		}
	}
	
	
}
